import { datalist } from '@/data.js'
export function mapFun (map) {
  function createInfoWindow (data) {
    let content = `<div style='color: aqua;width: 23.875rem;border: solid 2px #A0F487;border-radius: 5px;padding:1rem'>
          <p class="font_s22" style="color:#5AD834">| ${data.mc}</p>
          <p>
            <img class="verticM" style="height:1.125rem;margin-left:1rem;" src="${process.env.BASE_URL}img/02.png" alt="">&nbsp;&nbsp;
            <span class="Regular font_s18 colorF">公墓地址：${data.dz} </span>
          </p>
          <p>
            <img class="verticM" style="height:1.125rem;margin-left:1rem;" src="${process.env.BASE_URL}img/03.png" alt="">&nbsp;&nbsp;
            <span class="Regular font_s18 colorF">开办时间：${data.ksrq}</span>
          </p>
          <p>
            <img class="verticM" style="height:1.125rem;margin-left:1rem;" src="${process.env.BASE_URL}img/04.png" alt="">&nbsp;&nbsp;
            <span class="Regular font_s18 colorF">负 责 人 ：${data.fzr}</span>
          </p>
          <p>
            <img class="verticM" style="height:1.125rem;margin-left:1rem;" src="${process.env.BASE_URL}img/05.png" alt="">&nbsp;&nbsp;
            <span class="Regular font_s18 colorF">社会信用代码号：<br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;91310115676253729p</span>
          </p>
        </div>`
    // <p class="font_s18" style="color: #5AD834;padding-left: 3rem;"><span>公墓生命周期图</span></p>
    var info = document.createElement('div')
    info.className = 'custom-info input-card content-window-card'

    var middle = document.createElement('div')
    middle.className = 'info-middle'
    middle.style.backgroundColor = 'rgba(0,0,0,0.5)'
    middle.innerHTML = content
    info.appendChild(middle)
    return info
  }
  // 创建点
  // console.log(datalist)
  for (const elem of datalist.values()) {
    let arr = []
    arr.push(elem.jd)
    arr.push(elem.wd)
    elem.lnglat = arr
  }
  let infoWindow = new AMap.InfoWindow({ isCustom: true, offset: new AMap.Pixel(0, -30) })
  for (let i = 0, marker; i < datalist.length; i++) {
    marker = new AMap.Marker({
      position: datalist[i].lnglat,
      icon: datalist[i].type === '1' ? `${process.env.BASE_URL}img/01.png` : `${process.env.BASE_URL}img/08.png`,
      map: map
    })
    marker.content = createInfoWindow(datalist[i])
    marker.on('click', markerClick)
    marker.emit('click', { target: marker })
  }
  function markerClick (e) {
    infoWindow.setContent(e.target.content)
    if (e.pixel) { // 初始不打开弹窗
      infoWindow.open(map, e.target.getPosition())
    }
  }
  map.setFitView()
};
